package com.example.model23.test3;

/**
 * 简单工厂模式 + 策略模式
 */
// 客户端代码
public class SimpleFactoryStrategyDemo {
    public static void main(String[] args) {
        // 创建工厂管理实例
        VehicleFactoryManager manager = new VehicleFactoryManager();

        // 注册工厂
        manager.registerFactory("car", new CarFactory());
        manager.registerFactory("train", new TrainFactory());

        // 使用工厂管理实例创建交通工具
        Vehicle car = manager.createVehicle("car");
        Vehicle train = manager.createVehicle("train");

        // 将交通工具设置到上下文环境中
        Context carContext = new Context(car);
        Context trainContext = new Context(train);

        // 执行移动操作
        carContext.executeMove(); // 输出 "Car is moving"
        trainContext.executeMove(); // 输出 "Train is moving"
    }
}